import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/emergency/exercise_plan_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/application/special_list/process_nodes_entity.dart';

class DrillDetailsController extends GetxController with GetSingleTickerProviderStateMixin {
  /// 页面类型 1:演练计划 2:演练记录
  late int type;

  /// 主键id
  late String id;

  ///TabController 变量
  late TabController tabController;

  /// 数据实体
  ExercisePlanEntity entity = ExercisePlanEntity();

  /// 审批流程数据
  List<ProcessNodesEntity>? nodeList;

  @override
  void onInit() {
    super.onInit();
    // 获取数据
    final Map<String, dynamic> arguments = Get.arguments as Map<String, dynamic>;
    type = arguments['type'] as int;
    id = arguments['id'] as String;
    // 初始化tabController
    tabController = TabController(vsync: this, length: 4); //type == 1 ? 3 : 4);
    // 获取基本信息
    getDetailsData();
    if (type == 1) {
      // 获取演练审批流程数据
      getProcessListData();
    }
  }

  /// 获取详情数据
  void getDetailsData() async {
    // 获取基本信息接口
    final res = await HttpUtil().generateGetRequest<ExercisePlanEntity>(
      type == 1 ? Interface.getExercisePlan : Interface.getExercisePlanRecord,
      queryParameters: {'id': id},
    ).execute();
    res.onSuccess((result) {
      if (result.data != null) {
        entity = result.data!;
      }
      update();
    });
  }

  /// 获取流程列表数据
  void getProcessListData() async {
    // 获取流程列表接口
    final res = await HttpUtil().generateGetRequest<List<ProcessNodesEntity>>(
      Interface.getProcessArrangeRecord,
      queryParameters: {'emergencyPlansId': id, 'businessType': 'm1'},
    ).execute();
    res.onSuccess((result) {
      if (result.data != null) {
        nodeList = result.data!;
      }
      update();
    });
  }
}
